var a = getApp();

Page({
    data: {
        userId: "",
        baseUrl: a.globalData.baseUrl,
        page: 1,
        limit: 20,
        hasMore: !0,
        orderList: [],
        sharId: "",
        sharetype: ""
    },
    onLoad: function(t) {
        var e = this;
        if (e.data.hasMore) {
            e.setData({
                nickName: a.globalData.nickName,
                avatarUrl: a.globalData.avatarUrl,
                userId: wx.getStorageSync("userId")
            });
            var i = a.globalData.baseUrl + a.globalData.urlactivityOrderList;
            this.getinitData(i);
        }
    },
    getinitData: function(a) {
        var t = this;
        wx.request({
            url: a,
            data: {
                userId: t.data.userId,
                page: t.data.page,
                limit: t.data.limit
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var e = JSON.parse(a.data);
                if (0 != e.code) wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 2e3
                }); else {
                    console.log(e);
                    var i = t.data.page, r = t.data.orderList;
                    e.activityOrderList.length < t.data.limit ? t.setData({
                        orderList: r.concat(e.activityOrderList),
                        hasMore: !1,
                        page: i + 1
                    }) : t.setData({
                        orderList: r.concat(e.activityOrderList),
                        hasMore: !0,
                        page: i + 1
                    });
                }
            }
        });
    },
    onReady: function() {},
    actDetail: function(a) {
        var t = a.currentTarget.dataset.type, e = a.currentTarget.dataset.id;
        1 == t ? wx.navigateTo({
            url: "../collageDetails/collageDetails?id=" + e + "&type=" + t
        }) : 2 == t ? wx.navigateTo({
            url: "../activity/purchaseDetail?id=" + e + "&type=" + t
        }) : 3 == t && wx.navigateTo({
            url: "../activity/bargainDetails?id=" + e + "&type=" + t
        });
    },
    onReachBottom: function() {
        var a = this.data.baseUrl + "m/order/activityOrderList";
        this.getinitData(a);
    },
    invite: function(a) {
        var t = this;
        t.setData({
            id: a.currentTarget.dataset.id
        }), wx.navigateTo({
            url: "../collageDetails/collageDetailsInvite?orderId=" + t.data.id
        });
    },
    inviteBargain: function(a) {
        var t = this;
        t.setData({
            id: a.currentTarget.dataset.id
        }), wx.navigateTo({
            url: "../activity/bargainDetailsInvit?orderid=" + t.data.id
        });
    },
    cancelOrder: function(t) {
        var e = this, i = a.globalData.urlBase + a.globalData.urlCancleOrder;
        wx.request({
            url: i,
            data: {
                orderId: t.currentTarget.dataset.orderid,
                state: t.currentTarget.dataset.state
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var i = JSON.parse(t.data);
                if (0 != i.code) wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1500
                }); else {
                    e.setData({
                        page: 1,
                        limit: 20,
                        orderList: []
                    });
                    var r = a.globalData.baseUrl + a.globalData.urlactivityOrderList;
                    e.getinitData(r);
                }
            }
        });
    },
    getPayData: function(t) {
        var e = this, i = a.globalData.urlBase + a.globalData.urlPayData;
        wx.request({
            url: i,
            data: {
                orderId: t,
                userId: a.globalData.userId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var t = JSON.parse(a.data);
                0 != t.code ? wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                }) : e.wxPay(t);
            }
        });
    },
    wxPay: function(t) {
        var e = this;
        wx.requestPayment({
            timeStamp: t.timeStamp,
            nonceStr: t.nonceStr,
            package: "prepay_id=" + t.totalId,
            signType: "MD5",
            paySign: t.sign,
            success: function(a) {
                e.setData({
                    page: 1,
                    limit: 20,
                    orderList: []
                });
            },
            fail: function(a) {
                wx.showToast({
                    title: "支付失败",
                    icon: "none",
                    duration: 500
                });
            },
            complete: function(t) {
                var i = a.globalData.baseUrl + a.globalData.urlactivityOrderList;
                e.getinitData(i);
            }
        });
    },
    toPay: function(a) {
        this.getPayData(a.currentTarget.dataset.orderid);
    },
    onShareAppMessage: function() {}
});